def sample(x):
    for i in range(2, (x//2)+1):
        if x % i == 0:
            return False
    return True

a = int(input(" "))

if a < 10000 and a > 999:
    if sample(a):
        print(a)
        pass
    else:
        s = str(a)
        m_s = 0
        count_sn = 0
        for i in range(4):
            p1 = int(s[i])
            if sample(p1) and p1 > m_s:
                m_s = p1
                count_sn += 1
            for j in range(i+1, len(s)):
                p2 = int(s[i]+s[j])
                if sample(p2) and p2 > m_s:
                    m_s = p2
                    count_sn += 1
                for y in range(j+1, len(s)):
                    p3 = int(s[i]+s[j]+s[y])
                    if sample(p3) and p3 > m_s:
                        m_s = p3
                        count_sn += 1
        if count_sn != 0:
            print(m_s)
        else:
            print('0')
else:
    print('0')